package com.stone.design.patterns.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Stone
 * @version V1.0
 * @description:
 * @date 18/4/3 21:33
 * @email redsstone@163.com
 */
public class NotifyObserver implements Subject{

    private List<Observer> mObservers;

    public NotifyObserver() {
        mObservers = new ArrayList<>();
    }

    @Override
    public void registerObserver(Observer observer) {
        mObservers.add(observer);
    }

    @Override
    public void removeObserver(Observer observer) {
        int i = mObservers.indexOf(observer);
        if (i >= 0) {
            mObservers.remove(observer);
        }
    }

    @Override
    public void notifyObservers() {

        System.out.print(" >>>>>mObservers.size()>>>>>>>" + mObservers.size());
        System.out.println();
        for (Observer o: mObservers) {
            o.update("在吗？？？？");
        }
    }
}
